package com.central.user.service.impl;

import com.central.common.lock.DistributedLock;
import com.central.common.model.SysRole;
import com.central.common.model.SysUser;
import com.central.common.service.impl.SuperServiceImpl;
import com.central.user.mapper.SysRoleMenuMapper;
import com.central.user.mapper.SysUserAccountMapper;
import com.central.user.mapper.SysUserMapper;
import com.central.user.service.ISysRoleUserService;
import com.central.user.service.ISysUserService;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 作者 owen E-mail: 624191343@qq.com
 */
@Slf4j
@Service
public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Resource
    private SysUserAccountMapper userAccountMapper;

    @Autowired
    private DistributedLock lock;

    @Resource
    private ISysRoleUserService roleUserService;

    @Resource
    private SysRoleMenuMapper roleMenuMapper;

    @Override
    public SysUser findUserById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public SysUser getLoginAppUser(SysUser user) {
        if (user != null) {
            List<SysRole> sysRoles = roleUserService.findRolesByUserId(user.getId());
            // 设置角色
            user.setRoles(sysRoles);
            return user;
        }
        return null;
    }
}
